package com.zlzxm.shoesmarket.view.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.adapter.ADStatisticInfo;
import com.zlzxm.shoesmarket.view.adapter.ADStatisticMenu;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityStatisticInfo;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityStatisticMenu;
import com.zlzxm.shoesmarket.view.widget.simpleead.SimpleHead;
import com.zlzxm.shoesmarket.viewmodel.VMStatistic;

import java.util.List;

/**
 * CREATE BY zlzxm ON 4/7/21
 */
public class FMNavigationStatistic extends BaseFragment{

    private static final String TAG = "FMNavigationStatistic";

    private VMStatistic vmStatistic;

    private RecyclerView rvInfo,rvMenu;

    private ADStatisticInfo adStatisticInfo;

    private ADStatisticMenu adStatisticMenu;

    private  SimpleHead simpleHead;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_navigation_statistic,container,false);
    }

    @Override
    protected void initView(@NonNull View view, @NonNull Bundle savedInstanceState) {
        super.initView(view, savedInstanceState);
        Log.e(TAG,"initView");
        title = "统计";
        rvInfo = ZViewHelp.findById(view,R.id.rvInfo);
        rvInfo.setLayoutManager(new GridLayoutManager(getContext(),4));

        rvMenu = ZViewHelp.findById(view,R.id.rvMenu);
        rvMenu.setLayoutManager(new GridLayoutManager(getContext(),3));

        simpleHead = ZViewHelp.findById(view,R.id.head);


    }

    @Override
    protected void initViewModel() {
        super.initViewModel();
        Log.e(TAG,"initViewModel");
        vmStatistic = new ViewModelProvider(this).get(VMStatistic.class);

        vmStatistic.getLiveInfo().observe(this, new Observer<List<EntityStatisticInfo>>() {
            @Override
            public void onChanged(List<EntityStatisticInfo> infos) {
                Log.e(TAG,"getLiveInfo  onChanged");
                if(adStatisticInfo != null){

                    adStatisticInfo.setList(infos);
                }
            }
        });

        vmStatistic.getLiveMenu().observe(this, new Observer<List<EntityStatisticMenu>>() {
            @Override
            public void onChanged(List<EntityStatisticMenu> entityStatisticMenus) {

                if(adStatisticMenu != null){

                    adStatisticMenu.setList(entityStatisticMenus);
                }
            }
        });
    }



    @Override
    protected void initData() {
        super.initData();
        Log.e(TAG,"initData");
        simpleHead.setTitle(title);
        adStatisticInfo = new ADStatisticInfo(null);
        adStatisticMenu = new ADStatisticMenu(null);
        rvInfo.setAdapter(adStatisticInfo);
        rvMenu.setAdapter(adStatisticMenu);
    }
}
